#set(modelClass = cls.getModuleClass("model"))
#set(modelVar = cls.getModuleVar("model"))
#set(searchClass = cls.getModuleClass("vue.search"))
#set(searchFile = cls.getModuleKebabFile("vue.search"))
#set(formClass = cls.getModuleClass("vue.form"))
#set(formFile = cls.getModuleKebabFile("vue.form"))
#set(searchFds = cls.searchFields)
<script setup lang="ts">
import { $t } from '@/locales';
import { useNaiveForm } from '@/hooks/common/form';
#include("_formItem.tpl")
#for(f:searchFds)
#@importComponent(f)
#end
defineOptions({
  name: '#(searchClass)'
});

interface Emits {
  (e: 'search'): void;
}

const emit = defineEmits<Emits>();

const { formRef } = useNaiveForm();

const model = defineModel<Api.SearchParams>('model', { required: true });

const initialParams = { ...model.value };

async function reset() {
  Object.assign(model.value, initialParams);
}

async function search() {
  emit('search');
}
</script>

<template>
  <NCard :bordered="false" size="small" class="card-wrapper">
    <NCollapse :default-expanded-names="['form-search']">
      <NCollapseItem :title="$t('common.search')" name="form-search">
        <NForm ref="formRef" :model="model" label-placement="left" :label-width="80">
          <NGrid responsive="screen" item-responsive>
          #for(f:searchFds)
            #@renderSearchItem(f, 'model')
          #end
            <NFormItemGi span="24 s:12 m:6">
              <NSpace class="w-full" justify="end">
                <NButton @click="reset">
                  <template #icon>
                    <icon-ic-round-refresh class="text-icon" />
                  </template>
                  {{ $t('common.reset') }}
                </NButton>
                <NButton type="primary" ghost @click="search">
                  <template #icon>
                    <icon-ic-round-search class="text-icon" />
                  </template>
                  {{ $t('common.search') }}
                </NButton>
              </NSpace>
            </NFormItemGi>
          </NGrid>
        </NForm>
      </NCollapseItem>
    </NCollapse>
  </NCard>
</template>

<style scoped></style>
